//	Project:	HexTower
//	File:		DirectGraphics_Manager.h
//	Author:		Mustafa Aldoori
//	Purpose:	Graphics Manager to handle all textures and 3D objects.

#pragma once

// The include files for Direct3D9
#include <d3d9.h>
#include <d3dx9.h>

#include <tchar.h>
#include <vector>
using std::vector;

class DirectGraphics_Manager
{
private:
	// All the data we need to contain a texture.
	typedef struct _TEXTURE
	{
		TCHAR				filename[_MAX_PATH];	// The filename of this texture.
		int					ref;					// The number of times this texture has be loaded.
		LPDIRECT3DTEXTURE9	texture;				// A pointer to the texture.
		int					Width;					// The width of the texture.
		int					Height;					// The Height of the texture.

		// Default constructor.
		_TEXTURE()
		{
			filename[0] = '\0';
			ref = 0;
			texture = NULL;
			Width = 0;
			Height = 0;
		}
	} TEXTURE, *LPTEXTURE;

	vector<TEXTURE>				m_Textures;			// A list of all the loaded textures.
	LPDIRECT3DDEVICE9			m_lpDevice;			// A pointer to the Direct3D device.
	LPD3DXSPRITE				m_lpSprite;			// A pointer to the sprite interface.
	static DirectGraphics_Manager		m_Instance;			// An instance to this class.

	DirectGraphics_Manager( void );
	DirectGraphics_Manager( DirectGraphics_Manager &ref );
	DirectGraphics_Manager &operator=( DirectGraphics_Manager &ref );
	~DirectGraphics_Manager( void );
public:
	static				DirectGraphics_Manager* GetInstance( void );

	//	Purpose:	Initializes the texture manager.
	bool InitGraphics_Manager(LPDIRECT3DDEVICE9 lpDevice, LPD3DXSPRITE lpSprite);

	//	Purpose:	Unloads all the loaded textures and 
	//				releases references to sprite and d3d devices.
	void ShutdownTextureManager(void);

	//	Purpose:	To load a texture from a file. 
	//  NOTE:		Image dimensions must be a power of 2 (i.e. 256x64).
	//				Supports .bmp, .dds, .dib, .hdr, .jpg, .pfm, .png, 
	//				.ppm, and .tga files. 
	int LoadTexture( const TCHAR* szFilename, DWORD dwColorkey = 0 );

	//	Purpose:	Releases a reference to a given texture. When the
	//				reference to the texture is zero, the texture is
	//				released from memory.
	void UnloadTexture( int nID );

	//	Purpose:	Gets the width of a specified texture.
	int GetTextureWidth(int nID);

	//	Purpose:	Gets the height of a specified texture.
	int GetTextureHeight(int nID);

	//	Purpose:	Draws a texture to the screen.
	bool Draw(int nID, int nX, int nY, float fScaleX = 1.0f, float fScaleY = 1.0f,
		RECT* pSection = NULL, float fRotCenterX = 0.0f, float fRotCenterY = 0.0f, float fRotation = 0.0f, DWORD dwColor = 0xFFFFFFFF);

};

